<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <%@include file="../common.jsp"%>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="nickName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">手机号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">性别</label>
                            <div class="layui-input-inline">
                                <select name="sex">
                                    <option value="-1" selected>全部</option>
                                    <option value="1">男</option>
                                    <option value="0">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="status">
                                    <option value="-1" selected>全部</option>
                                    <option value="0">正常</option>
                                    <option value="1">异常</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="recover">恢复</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="abandon">禁用</a>
        </script>

    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>


    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: SITE_BASE_PATH + '/user/list.do',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'nickName', width: 100, title: '昵称'},
                {field: 'sex', width: 80, title: '性别',templet:function (data) {
                        if(data.sex==0){
                            return '女';
                        }else if(data.sex==1){
                            return '男';
                        }
                    }},
                {field: 'phone', width: 130, title: '手机号'},
                {field: 'age', width: 80, title: '年龄'},
                {field: 'createTime', width: 120, title: '创建时间'},
                {field: 'lastTime', width: 120, title: '上次登陆时间'},
                {field: 'status', width: 120, title: '用户状态',templet:function (data) {
                        if(data.status==0){
                            return '<div style="color: green">正常</div>';
                        }else if(data.status==1){
                            return '<div style="color:red">异常</div>';
                        }
                    }},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {

            console.log(data.field);

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    'nickName': data.field.nickName,
                    'phone': data.field.phone,
                    'sex':data.field.sex,
                    'status': data.field.status
                }
            }, 'data');

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'recover') {
                layer.confirm('确定要恢复嘛',function (index) {
                    data.status = 0;
                    layer.close(index);
                })
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'abandon') {
                layer.confirm('确定要禁用嘛', function (index) {
                    data.status = 1;
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>